/**
 * Created by no1 on 2015/7/23.
 */
'use strict';
var DaoBase = require('./DaoBase');
var db = require('./models');
var F = require('../../function');

var util = require("util");

function VendorDao(data) {
  data = data || {}
  data.model = data.model || db.vendor;
  this.data = data;
  DaoBase.call(this, this.data);
};
util.inherits(VendorDao, DaoBase);

/*
 @todo 查询
 @ pipeline 条件
 @ opt 参数
 */
VendorDao.prototype.getByAggregate = function*(pipeline, opt) {
  if (!pipeline) return F.returnData(1, '没有参数.')
  let ret = yield this.model.aggregate(pipeline).exec();
  if (ret.errors) return F.returnData(1, ret.errors, ret);
  return F.returnData(0, '查询成功.', ret)
};

VendorDao.prototype.findOne = function*(condition, opt) {
  let ret = {};
  if (!opt) {
    ret = yield  this.model.findOne(condition).exec();
  } else {
    ret = yield  this.model.findOne(condition, opt).exec();
  }
  if (ret.errors) {
    return {}
  }
  return ret;
}

module.exports = VendorDao;